home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / MSJV7_2B.ARJ / REGISTER.C < prev    next >
C/C++ Source or Header  |  1992-03-01  |  7KB  |  194 lines

  1. /*
  2.  * register.c - Handles the Win 3.1 registration library.
  3.  *
  4.  * Created by Microsoft Corporation.
  5.  * (c) Copyright Microsoft Corp. 1990 - 1992  All Rights Reserved
  6.  */
  7.  
  8. //*** INCLUDES ***
  9.  
  10. #include <windows.h>
  11. #include <shellapi.h>
  12. #include <ole.h>
  13.  
  14. #include "global.h"
  15. #include "register.h"
  16. #include "clidemo.h"     
  17. #include "demorc.h"   
  18.  
  19. /****************************************************************************
  20.  * RegGetClassId() - Retrieves the string name of a class.
  21.  *
  22.  * Retrieve the string name of a class. Classes are guarenteed to be 
  23.  * in ASCII, but should not be used directly as a rule because they
  24.  * might be meaningless if running non-English Windows.
  25.  ***************************************************************************/
  26.  
  27. void FAR RegGetClassId(                //* ENTRY:
  28.    LPSTR          lpstrName,           //* destination string name of class
  29.    LPSTR          lpstrClass           //* source name of class
  30. ){                                     //* LOCAL:
  31.   DWORD           dwSize = KEYNAMESIZE;//* size of keyname string 
  32.   char            szName[KEYNAMESIZE]; //* string name for class 
  33.  
  34.    if (!RegQueryValue(HKEY_CLASSES_ROOT, lpstrClass, (LPSTR)szName, &dwSize))
  35.        lstrcpy(lpstrName, (LPSTR)szName);
  36.    else
  37.        lstrcpy(lpstrName, lpstrClass);
  38.  
  39. }
  40.  
  41.  
  42.  
  43. /***************************************************************************
  44.  *  RegMakeFilterSpec() - Retrieves class-associated default extensions.
  45.  *
  46.  * Get the class-associated default extensions, and build a filter spec, 
  47.  * to be used in the "Change Link" standard dialog box, which contains 
  48.  * all the default extensions which are associated with the given class 
  49.  * name.  Again, the class names are guaranteed to be in ASCII.
  50.  *
  51.  * Returns int - The index idFilterIndex states which filter item 
  52.  *               matches the extension, or 0 if none is found.
  53.  ***************************************************************************/
  54.  
  55. int FAR RegMakeFilterSpec(             //* ENTRY:
  56.    LPSTR          lpstrClass,          //* class name
  57.    LPSTR          lpstrExt,            //* file extension
  58.    LPSTR          lpstrFilterSpec      //* destination filter spec
  59. ){                                     //* LOCAL:
  60.    DWORD          dwSize;              //* size of reg request
  61.    char           szClass[KEYNAMESIZE];//* class name 
  62.    char           szName[KEYNAMESIZE]; //* name of subkey 
  63.    char           szString[KEYNAMESIZE];//* name of subkey 
  64.    unsigned int   i;                    //* index of subkey query 
  65.    int            idWhich = 0;          //* index of combo box item 
  66.    int            idFilterIndex = 0;    //* index to filter matching extension 
  67.  
  68.    for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szName, KEYNAMESIZE); ) 
  69.    {
  70.       if (  *szName == '.'             //* Default Extension...
  71.             && (dwSize = KEYNAMESIZE)
  72.             && !RegQueryValue(HKEY_CLASSES_ROOT, szName, szClass, &dwSize)
  73.             && (!lpstrClass || !lstrcmpi(lpstrClass, szClass))
  74.             && (dwSize = KEYNAMESIZE)
  75.             && !RegQueryValue(HKEY_CLASSES_ROOT, szClass, szString, &dwSize)) 
  76.       {
  77.          idWhich++;    
  78.  
  79.          if (lpstrExt && !lstrcmpi(lpstrExt, szName))
  80.             idFilterIndex = idWhich;
  81.                                        //* Copy over "<Class Name String> 
  82.                                        //* (*<Default Extension>)"
  83.                                        //* e.g. "Server Picture (*.PIC)"
  84.          lstrcpy(lpstrFilterSpec, szString);
  85.          lstrcat(lpstrFilterSpec, " (*");
  86.          lstrcat(lpstrFilterSpec, szName);
  87.          lstrcat(lpstrFilterSpec, ")");
  88.          lpstrFilterSpec += lstrlen(lpstrFilterSpec) + 1;
  89.                                        //* Copy over "*<Default Extension>" 
  90.                                        //* (e.g. "*.PIC") */
  91.          lstrcpy(lpstrFilterSpec, "*");
  92.          lstrcat(lpstrFilterSpec, szName);
  93.          lpstrFilterSpec += lstrlen(lpstrFilterSpec) + 1;
  94.       }
  95.    }
  96.    
  97.    *lpstrFilterSpec = 0;
  98.  
  99.    return idFilterIndex;
  100.  
  101. }
  102.  
  103.  
  104.  
  105. /***************************************************************************
  106.  *  RegCopyClassName()
  107.  *
  108.  *  Get the class name from the registration data base.  We have the
  109.  *  descriptive name and we search for the class name.
  110.  *
  111.  *  returns BOOL - TRUE if class name was found and retrieved from the
  112.  *                 registration database.
  113.  ***************************************************************************/
  114.  
  115. BOOL FAR RegCopyClassName(             //* ENTRY:
  116.    HWND           hwndList,            //* HANDLE to list box 
  117.    LPSTR          lpstrClassName       //* destination character string
  118. ){                                     //* LOCAL:
  119.    DWORD          dwSize;              //* key name size
  120.    HKEY           hkeyTemp;            //* temp key
  121.    char           szClass[KEYNAMESIZE];//* class name string
  122.    char           szKey[KEYNAMESIZE];  //* key name string
  123.    int            i;                   //* index
  124.  
  125.    if (!RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hkeyTemp)) 
  126.    {
  127.       i = (int)SendMessage(hwndList, LB_GETCURSEL, 0, 0L);
  128.       SendMessage(hwndList, LB_GETTEXT, i, (DWORD)(LPSTR)szKey);
  129.  
  130.       for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szClass, KEYNAMESIZE); )
  131.          if (*szClass != '.') 
  132.          {
  133.             dwSize = KEYNAMESIZE;
  134.             if (!RegQueryValue(HKEY_CLASSES_ROOT, szClass, lpstrClassName, &dwSize))
  135.                if (!lstrcmp(lpstrClassName, szKey))
  136.                {
  137.                     RegCloseKey(hkeyTemp);
  138.                     lstrcpy(lpstrClassName,szClass);    
  139.                     return TRUE;
  140.                 }
  141.          }
  142.       RegCloseKey(hkeyTemp);
  143.    }
  144.  
  145.    *lpstrClassName = NULL;
  146.    return FALSE;
  147.  
  148. }
  149.  
  150.  
  151.  
  152. /***************************************************************************
  153.  *  RegGetClassNames()
  154.  *
  155.  *  Fills in the list box in the Insert New dialog with the names of 
  156.  *  OLE Servers.
  157.  *
  158.  *  returns TRUE if the listbox filled successfully.
  159.  **************************************************************************/
  160.  
  161. BOOL FAR RegGetClassNames(       //* ENTRY:
  162.    HWND hwndList                 //* HANDLE to the listbox being filled
  163. ){                               //* LOCAL:
  164.    DWORD    dwSize;              //* sixe of data
  165.    HKEY     hkeyTemp;            //* temporary registration key
  166.    char     szExec[KEYNAMESIZE]; //* executables name 
  167.    char     szClass[KEYNAMESIZE];//* class name
  168.    char     szName[KEYNAMESIZE]; //* key name
  169.    int      i;                   
  170.  
  171.    SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);
  172.  
  173.    if (!RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hkeyTemp)) 
  174.    {
  175.       for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szClass, KEYNAMESIZE); )
  176.          if (*szClass != '.') 
  177.          {         
  178.             lstrcpy(szExec, szClass);
  179.             lstrcat(szExec, "\\protocol\\StdFileEditing\\server");
  180.             dwSize = KEYNAMESIZE;
  181.             if (!RegQueryValue(HKEY_CLASSES_ROOT, szExec, szName, &dwSize)) 
  182.             {
  183.                dwSize = KEYNAMESIZE;
  184.                if (!RegQueryValue(HKEY_CLASSES_ROOT, szClass, szName, &dwSize)) 
  185.                   SendMessage(hwndList, LB_ADDSTRING, 0, (DWORD)(LPSTR)szName);
  186.             }
  187.          }
  188.       RegCloseKey(hkeyTemp);
  189.       return TRUE;
  190.    }
  191.    return FALSE;
  192.  
  193. }
  194.